#! /usr/bin/env python

"""This sample came from
http://pycoders-weekly-chinese.readthedocs.org/en/latest/issue6/processing-xml-in-python-with-element-tree.html
"""

try:
    import xml.etree.cElementTree as ET
except ImportError:
    import xml.etree.ElementTree as ET

tree = ET.ElementTree(file='doc1.xml')
root = tree.getroot()

for child_of_root in root:
    print child_of_root.tag, child_of_root.attrib

print "\n................\n"

for elem in tree.iter():
    print elem.tag, elem.attrib

print "\n................\n"

for elem in tree.iter(tag='branch'):
    print elem.tag, elem.attrib

print "\n................\n"

for elem in tree.iterfind('branch/sub-branch'):
    print elem.tag, elem.attrib

print "\n................\n"

for elem in tree.iterfind('branch[@name="release01"]'):
    print elem.tag, elem.attrib
